const request   = require('request');
const logger    = require('./log');
const config    = require('../crawler/config/config');

class rest_template{

    /**
     * GET request
     * @param options
     */
    static get(options){
        return new Promise(((resolve, reject) => {
            logger.debug(`Request options:${JSON.stringify(options.url)}`);
            options.timeout = config.REQUEST.TIME_OUT;
            request(options,(error, response, body) => {
                if(!error && response.statusCode === 200){
                    logger.info(`Status:[Successful].`);
                    resolve(body);
                }else{
                    logger.warn(`Status:[Failed]. exMsg:${error}`);
                    reject(error)
                }
            })

        }))
    }
}
module.exports = rest_template;
